package 二叉树;

public class LC_238把二叉搜索树转化为累加树 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    int pre=0;
    public TreeNode convertBST(TreeNode root) {
        if(root==null)
            return null;
        //右中左
        root.right=convertBST(root.right);
        root.val+=pre;
        pre=root.val;
        root.left=convertBST(root.left);
        return root;
    }
}
